import {Component, ElementRef, ViewChild} from '@angular/core';
import {Sys} from '../utils/sys';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent {
	constructor () {}

	option: any = {
		serverUrl: 'assets/mock/tableData.json',
		pluginTest: true,// 组件测试，只用于源码测试，产品环境忽略该属性
		columns: {
			filter: {
				enabled: true
			},
			batch: {
				enabled: true,
				checkAllName: null,
				checkSingleName: null
			},
			items: [{
				label: '系统编号',
				colName: 'c_id',
				visible: false,
				order: false,
				width: null,
				cls: 'text-center',
				style: null,
				ellipsis: false,
				filterProp: {
					enabled: true,
					type: 'string',
					compare: 'like' // like,=,>,<,between
				},
				render: (obj) => {
				}
			}, {
				label: '操作人',
				colName: 'c_name',
				visible: true,
				order: true,
				width: null,
				cls: 'text-center',
				style: null,
				ellipsis: false,
				filterProp: {
					enabled: true,
					type: 'string',
					compare: 'like' // like,=,>,<,between
				},
				render: (obj) => {
					return obj.c_name ? obj.c_name : '/';
				}
			}, {
				label: '请求方法',
				colName: 'c_method',
				visible: true,
				order: true,
				width: null,
				cls: 'text-center',
				style: null,
				ellipsis: false,
				filterProp: {
					enabled: true,
					type: 'string',
					compare: 'like' // like,=,>,<,between
				},
				render: (obj) => {
					return obj.c_method ? obj.c_method : '/';
				}
			}, {
				label: '请求参数',
				colName: 'c_parameter',
				visible: true,
				order: true,
				width: null,
				cls: 'text-center',
				style: null,
				ellipsis: false,
				filterProp: {
					enabled: true,
					type: 'string',
					compare: 'like' // like,=,>,<,between
				},
				render: (obj) => {
					return obj.c_parameter ? obj.c_parameter.split(']')[0] + ']' : '/';
				}
			}, {
				label: '请求路径',
				colName: 'c_class',
				visible: true,
				order: true,
				width: null,
				cls: 'text-center',
				style: null,
				ellipsis: false,
				filterProp: {
					enabled: true,
					type: 'string',
					compare: 'like' // like,=,>,<,between
				},
				render: (obj) => {
					return obj.c_class ? obj.c_class : '/';
				}
			}, {
				label: '操作时间',
				colName: 'd_date',
				visible: true,
				order: true,
				width: null,
				cls: 'text-center',
				style: null,
				ellipsis: false,
				filterProp: {
					enabled: true,
					type: 'date',  // string,select,date,datetime,num,combobox
					compare: 'like' // like,=,>,<,between
				},
				render: (obj) => {
					return obj.d_date ? Sys.dateFormat(new Date(obj.d_date), 'yyyy-MM-dd') : '/';
				}
			}]
		}
	};

	tableReady () {
		console.log('X-table is ready.');
	}
}
